package top.leyi.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.leyi.IService.IDataService;
import top.leyi.entity.SQLUtil;
import top.leyi.entity.data.Data;
import top.leyi.entity.data.Type;
import top.leyi.entity.user.User;
import top.leyi.mapper.DataMappper;

import java.util.List;

@Service
public class DataServiceImpl implements IDataService {
    private  final  int LIMIT = 25;
    @Autowired
    DataMappper dataMappper;
    @Override
    public List<Data> getAllData(int offset, String key) {

        SQLUtil util = new SQLUtil();
        util.setOffset((offset - 1)*LIMIT);
        util.setLimit(LIMIT);
        util.setKey(key);
        return dataMappper.fuzzyQueryData(util);
    }

    @Override
    public List<Data> getAllDataWithType(int offset,String key, String type) {
        SQLUtil util = new SQLUtil();
        util.setOffset((offset - 1)*LIMIT);
        util.setLimit(LIMIT);
        util.setKey(key);
        util.setType(type);
        return dataMappper.queryDataWithType(util );
    }

    @Override
    public List<Type> getAllDataType() {
        return dataMappper.getAllType();
    }

    @Override
    public void removeData(Data data, User user) {
        dataMappper.removeData(data.getId());
    }

    @Override
    public void addData(Data data, User user) {
        dataMappper.addData(data);

    }
}
